from core.learning.error_functions.error_function import ErrorFunction

__author__ = 'Douglas'


class RMS(ErrorFunction):
    def __init__(self):
        self.global_error = 0.0
        """:type : float"""

        self.size = 0
        """:type : int"""

    @property
    def total_error(self):
        return (self.global_error / self.size) ** 0.5

    def add_error(self, actual_output, ideal_output):
        self.global_error += sum([(ideal - actual) ** 2 for actual, ideal in zip(actual_output, ideal_output)])
        self.size += len(actual_output)

    def reset(self):
        self.global_error = 0.0
        self.size = 0.0